package com.zoshine.zzg.pojo.pojostatus;

import com.zoshine.zzg.base.Status;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 商品状态枚举
 *
 * @author 贾俊峰
 * @time 2017/6/20 17:42
 */
public enum InvoiceStatus {
	DELIVERY(1, "待发货"),
	FINISH(2, "已发货"),
    RELEASE(3, "已生成发放单"),
    OUT_OF_STOCK(4,"缺货"),
    PENDING_AUDIT(5,"已导入内网"),
    CONFIRM(6, "已收货"),
    SETTLEMENT(9,"已生成结算单");

    private int value;
    private String desc;
    InvoiceStatus(final int value, final String desc) {
        this.value = value;
        this.desc = desc;
    }

    public int getValue() {
        return value;
    }

    public static String getDesc(Integer value) {
        for (InvoiceStatus goodsStatus : InvoiceStatus.values()) {
            if (Objects.equals(goodsStatus.value, value)) {
                return goodsStatus.desc;
            }
        }
        return null;
    }

    // 缓存一个列表，防止每次使用都进行循环
    private static List<Status> statusList;
    public static List<Status> getList() {
        if (statusList == null || statusList.size() == 0) {
            statusList = new ArrayList<>();
            for (InvoiceStatus commonStatus : InvoiceStatus.values()) {
                // 将状态存入列表
                Status status = new Status();
                status.setValue(commonStatus.value);
                status.setDesc(commonStatus.desc);
                statusList.add(status);
            }
        }
        return statusList;
    }
}
